using ASP;
using HoWave.Common;
using HoWave.Web;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.UI;
using System.Web.UI.WebControls;
public class Shop_UserControls_IdentifyProvinceCity : UserControl
{
	protected ScriptManager ScriptManager1;
	protected DropDownList Province;
	protected DropDownList City;
	protected UpdatePanel UpdatePanel1sa;
	private Conn conn = null;
	private Shop_City _city;
	private string m_selectedProv;
	private string m_selectedCity;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected Shop_City m_city
	{
		get
		{
			Shop_City city;
			if (this._city == null)
			{
				this._city = new Shop_City();
				city = this._city;
			}
			else
			{
				city = this._city;
			}
			return city;
		}
	}
	public string SelectedProvince
	{
		get
		{
			return this.Province.SelectedValue;
		}
		set
		{
			this.m_selectedProv = value;
		}
	}
	public string SelectedCity
	{
		get
		{
			return this.City.SelectedValue;
		}
		set
		{
			this.m_selectedCity = value;
		}
	}
	public string SelectedText
	{
		get
		{
			return this.Province.SelectedValue + this.City.SelectedValue;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!base.IsPostBack)
		{
			this.Bind();
		}
		base.Error += new EventHandler(this.Shop_UserControls_HowaveProvinceCity_Error);
	}
	private void Shop_UserControls_HowaveProvinceCity_Error(object sender, EventArgs e)
	{
		if (this.conn != null)
		{
			this.conn.CloseConn();
		}
	}
	protected void Province_Changed(object seder, EventArgs e)
	{
		this.GetCity();
	}
	public void Bind()
	{
		this.BindProvince();
		this.BindCity();
	}
	protected void BindProvince()
	{
		DataTable allProvince = this.m_city.GetAllProvince();
		this.Province.Items.Clear();
		ListItem item = new ListItem(Language.Get("Common/Choose"), "");
		this.Province.Items.Add(item);
		this.Province.DataSource = allProvince;
		this.Province.DataTextField = "Province";
		this.Province.DataValueField = "Province";
		this.Province.DataBind();
		if (this.m_selectedProv != null && this.m_selectedProv != "")
		{
			foreach (ListItem listItem in this.Province.Items)
			{
				listItem.Selected = (listItem.Value == this.m_selectedProv);
			}
		}
	}
	protected void BindCity()
	{
		if (this.Province.SelectedIndex != 0)
		{
			this.GetCity();
			foreach (ListItem listItem in this.City.Items)
			{
				if (listItem.Value == this.m_selectedCity)
				{
					listItem.Selected = true;
				}
			}
		}
	}
	protected void GetCity()
	{
		this.City.Items.Clear();
		this.City.Items.Add(new ListItem(Language.Get("Common/Choose"), ""));
		if (this.Province.SelectedIndex != 0)
		{
			DataTable city = this.m_city.GetCity(this.Province.SelectedValue);
			if (city != null && city.Rows.Count > 0)
			{
				this.City.DataSource = city;
				this.City.DataTextField = "city";
				this.City.DataValueField = "city";
				this.City.DataBind();
			}
		}
	}
}
